package com.yundasys.lab12java.orm;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

/**
 * @author jiangta
 * @version 1.0
 * @date 2021/5/7 9:08 上午
 */
public class ORMDemo {

    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException {
        // 获取Student 的 Class对象
        Class c1 = Class.forName("com.yundasys.lab12java.orm.Student2");

        // 通过反射，获取到全部注解
        Annotation[] annotations = c1.getAnnotations();
        for(Annotation annotation: annotations) {
            System.out.println(annotation);
        }

        // 获取注解的value值
        TableKuang taleKuang = (TableKuang) c1.getAnnotation(TableKuang.class);
        String value = taleKuang.value();
        System.out.println(value);

        // 获得类指定的注解
        Field name = c1.getDeclaredField("name");
        FieldKuang fieldKuang = name.getAnnotation(FieldKuang.class);
        System.out.println(fieldKuang.columnName());
        System.out.println(fieldKuang.length());
        System.out.println(fieldKuang.type());

    }
}
